package com.itheima.grow.controller;

import com.itheima.grow.model.info.OssFileInfo;
import com.itheima.grow.model.other.Result;
import com.itheima.grow.util.ZipUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/zip")
public class ZipController {

    @PostMapping("/downZip")
    public void downZip(@RequestBody List<String> fileUrls) throws IOException {
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletResponse response = servletRequestAttributes.getResponse();
        ZipUtil.createZipFile(fileUrls,response);
    }
}
